package o;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.WeakHashMap;

public final class ar {
    private static final ThreadLocal<TypedValue> ˊ = new ThreadLocal();
    private static final Object ˎ = new Object();
    private static final WeakHashMap<Context, SparseArray<d>> ˏ = new WeakHashMap(0);

    static class d {
        final Configuration ˊ;
        final ColorStateList ˋ;

        d(@NonNull ColorStateList colorStateList, @NonNull Configuration configuration) {
            this.ˋ = colorStateList;
            this.ˊ = configuration;
        }
    }

    public static ColorStateList ˊ(@NonNull Context context, @ColorRes int i) {
        if (VERSION.SDK_INT >= 23) {
            return context.getColorStateList(i);
        }
        ColorStateList ˎ = ˎ(context, i);
        if (ˎ != null) {
            return ˎ;
        }
        ˎ = ॱ(context, i);
        if (ˎ == null) {
            return fo.ॱ(context, i);
        }
        ˏ(context, i, ˎ);
        return ˎ;
    }

    @Nullable
    public static Drawable ˋ(@NonNull Context context, @DrawableRes int i) {
        return bx.ˋ().ˎ(context, i);
    }

    @Nullable
    private static ColorStateList ॱ(Context context, int i) {
        ColorStateList colorStateList = null;
        if (!ˏ(context, i)) {
            Resources resources = context.getResources();
            try {
                colorStateList = fp.ˊ(resources, resources.getXml(i), context.getTheme());
            } catch (Throwable e) {
                Log.e("AppCompatResources", "Failed to inflate ColorStateList, leaving it to the framework", e);
            }
        }
        return colorStateList;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    @androidx.annotation.Nullable
    private static android.content.res.ColorStateList ˎ(@androidx.annotation.NonNull android.content.Context r5, @androidx.annotation.ColorRes int r6) {
        /*
        r2 = ˎ;
        monitor-enter(r2);
        r0 = ˏ;	 Catch:{ all -> 0x0035 }
        r0 = r0.get(r5);	 Catch:{ all -> 0x0035 }
        r0 = (android.util.SparseArray) r0;	 Catch:{ all -> 0x0035 }
        if (r0 == 0) goto L_0x0032;
    L_0x000d:
        r1 = r0.size();	 Catch:{ all -> 0x0035 }
        if (r1 <= 0) goto L_0x0032;
    L_0x0013:
        r1 = r0.get(r6);	 Catch:{ all -> 0x0035 }
        r1 = (o.ar.d) r1;	 Catch:{ all -> 0x0035 }
        if (r1 == 0) goto L_0x0032;
    L_0x001b:
        r3 = r1.ˊ;	 Catch:{ all -> 0x0035 }
        r4 = r5.getResources();	 Catch:{ all -> 0x0035 }
        r4 = r4.getConfiguration();	 Catch:{ all -> 0x0035 }
        r3 = r3.equals(r4);	 Catch:{ all -> 0x0035 }
        if (r3 == 0) goto L_0x002f;
    L_0x002b:
        r0 = r1.ˋ;	 Catch:{ all -> 0x0035 }
        monitor-exit(r2);	 Catch:{ all -> 0x0035 }
    L_0x002e:
        return r0;
    L_0x002f:
        r0.remove(r6);	 Catch:{ all -> 0x0035 }
    L_0x0032:
        monitor-exit(r2);	 Catch:{ all -> 0x0035 }
        r0 = 0;
        goto L_0x002e;
    L_0x0035:
        r0 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x0035 }
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.ar.ˎ(android.content.Context, int):android.content.res.ColorStateList");
    }

    private static void ˏ(@NonNull Context context, @ColorRes int i, @NonNull ColorStateList colorStateList) {
        synchronized (ˎ) {
            SparseArray sparseArray = (SparseArray) ˏ.get(context);
            if (sparseArray == null) {
                sparseArray = new SparseArray();
                ˏ.put(context, sparseArray);
            }
            sparseArray.append(i, new d(colorStateList, context.getResources().getConfiguration()));
        }
    }

    private static boolean ˏ(@NonNull Context context, @ColorRes int i) {
        Resources resources = context.getResources();
        TypedValue ˊ = ˊ();
        resources.getValue(i, ˊ, true);
        if (ˊ.type < 28 || ˊ.type > 31) {
            return false;
        }
        return true;
    }

    @NonNull
    private static TypedValue ˊ() {
        TypedValue typedValue = (TypedValue) ˊ.get();
        if (typedValue != null) {
            return typedValue;
        }
        typedValue = new TypedValue();
        ˊ.set(typedValue);
        return typedValue;
    }
}
